// 基础设施 / 房间管理
import r from '@/utils/request'
import { type ListResponseType, type ResponseType, type ListParams } from '../types'

enum API {
    houseList = "/house/list", // 房间列表
    houseAdd = "/house/add", // 房间添加
    houseUpdate = "/house/update", // 房间修改
    houseDelete = "/house/delete", // 房间删除
    houseDeleteAll = "/house/deleteAll", // 房间删除
}

export interface HouseListParams extends ListParams {
    name?: string;
    buildingId?: number;
}

export interface HouseListResAPI {
    id:             number;
    companyId:      number;
    buildingId:     number;
    buildingName:   string;
    type:           number;
    typeName:       string;
    name:           string;
    beds:           number;
    picture:        string;
    addTime:        string;
    addAccountId:   number;
    addAccountName: string;
}

export function getHouseListAPI(Params:HouseListParams):Promise<ListResponseType<HouseListResAPI>> {
    return r.get(API.houseList,Params)
}

export interface  houseAddAndUpdateParams {
    id:         number;
    buildingId: number;
    type:       number | string;
    name:       string;
    beds:       number ;
    picture:    string;
}

export interface houseAddAndUpdateResAPI {
    id:             number;
    companyId:      number;
    buildingId:     number;
    buildingName:   string;
    type:           number;
    typeName:       string;
    name:           string;
    beds:           number;
    picture:        string;
    addTime:        string;
    addAccountId:   number;
    addAccountName: string;
}

export function houseAddAPI(Params:houseAddAndUpdateParams):Promise<ResponseType<houseAddAndUpdateResAPI>> {
    return r.post(API.houseAdd,Params)
}

export function houseUpdateAPI(Params:houseAddAndUpdateParams):Promise<ResponseType<houseAddAndUpdateResAPI>> {
    return r.put(API.houseUpdate,Params)
}

export function houseDeleteAPI(id:number):Promise<ResponseType<null>> {
    return r.delete(API.houseDelete+'/'+id)
}

export function houseDeleteAllAPI(ids:number[]):Promise<ResponseType<null>> {
    return r.post(API.houseDeleteAll,ids)
}